using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace Medianamik.Core.DAL.SubSonicDAL
{
	/// <summary>
	/// Strongly-typed collection for the NodeInstance class.
	/// </summary>
    [Serializable]
	public partial class NodeInstanceCollection : ActiveList<NodeInstance, NodeInstanceCollection>
	{	   
		public NodeInstanceCollection() {}
        
        /// <summary>
		/// Filters an existing collection based on the set criteria. This is an in-memory filter
		/// Thanks to developingchris for this!
        /// </summary>
        /// <returns>NodeInstanceCollection</returns>
		public NodeInstanceCollection Filter()
        {
            for (int i = this.Count - 1; i > -1; i--)
            {
                NodeInstance o = this[i];
                foreach (SubSonic.Where w in this.wheres)
                {
                    bool remove = false;
                    System.Reflection.PropertyInfo pi = o.GetType().GetProperty(w.ColumnName);
                    if (pi.CanRead)
                    {
                        object val = pi.GetValue(o, null);
                        switch (w.Comparison)
                        {
                            case SubSonic.Comparison.Equals:
                                if (!val.Equals(w.ParameterValue))
                                {
                                    remove = true;
                                }
                                break;
                        }
                    }
                    if (remove)
                    {
                        this.Remove(o);
                        break;
                    }
                }
            }
            return this;
        }
		
		
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the medianamik_NodeInstance table.
	/// </summary>
	[Serializable]
	public partial class NodeInstance : ActiveRecord<NodeInstance>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public NodeInstance()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public NodeInstance(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public NodeInstance(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public NodeInstance(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("medianamik_NodeInstance", TableType.Table, DataService.GetInstance("MedianamikProvider"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarNodeInstanceId = new TableSchema.TableColumn(schema);
				colvarNodeInstanceId.ColumnName = "NodeInstanceId";
				colvarNodeInstanceId.DataType = DbType.Guid;
				colvarNodeInstanceId.MaxLength = 0;
				colvarNodeInstanceId.AutoIncrement = false;
				colvarNodeInstanceId.IsNullable = false;
				colvarNodeInstanceId.IsPrimaryKey = true;
				colvarNodeInstanceId.IsForeignKey = false;
				colvarNodeInstanceId.IsReadOnly = false;
				colvarNodeInstanceId.DefaultSetting = @"";
				colvarNodeInstanceId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarNodeInstanceId);
				
				TableSchema.TableColumn colvarNodeId = new TableSchema.TableColumn(schema);
				colvarNodeId.ColumnName = "NodeId";
				colvarNodeId.DataType = DbType.Guid;
				colvarNodeId.MaxLength = 0;
				colvarNodeId.AutoIncrement = false;
				colvarNodeId.IsNullable = false;
				colvarNodeId.IsPrimaryKey = false;
				colvarNodeId.IsForeignKey = true;
				colvarNodeId.IsReadOnly = false;
				colvarNodeId.DefaultSetting = @"";
				
					colvarNodeId.ForeignKeyTableName = "medianamik_Node";
				schema.Columns.Add(colvarNodeId);
				
				TableSchema.TableColumn colvarIsActive = new TableSchema.TableColumn(schema);
				colvarIsActive.ColumnName = "IsActive";
				colvarIsActive.DataType = DbType.Boolean;
				colvarIsActive.MaxLength = 0;
				colvarIsActive.AutoIncrement = false;
				colvarIsActive.IsNullable = false;
				colvarIsActive.IsPrimaryKey = false;
				colvarIsActive.IsForeignKey = false;
				colvarIsActive.IsReadOnly = false;
				
						colvarIsActive.DefaultSetting = @"((1))";
				colvarIsActive.ForeignKeyTableName = "";
				schema.Columns.Add(colvarIsActive);
				
				TableSchema.TableColumn colvarCreatedOn = new TableSchema.TableColumn(schema);
				colvarCreatedOn.ColumnName = "CreatedOn";
				colvarCreatedOn.DataType = DbType.DateTime;
				colvarCreatedOn.MaxLength = 0;
				colvarCreatedOn.AutoIncrement = false;
				colvarCreatedOn.IsNullable = false;
				colvarCreatedOn.IsPrimaryKey = false;
				colvarCreatedOn.IsForeignKey = false;
				colvarCreatedOn.IsReadOnly = false;
				
						colvarCreatedOn.DefaultSetting = @"(getdate())";
				colvarCreatedOn.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreatedOn);
				
				TableSchema.TableColumn colvarCultureName = new TableSchema.TableColumn(schema);
				colvarCultureName.ColumnName = "CultureName";
				colvarCultureName.DataType = DbType.String;
				colvarCultureName.MaxLength = 10;
				colvarCultureName.AutoIncrement = false;
				colvarCultureName.IsNullable = false;
				colvarCultureName.IsPrimaryKey = false;
				colvarCultureName.IsForeignKey = true;
				colvarCultureName.IsReadOnly = false;
				colvarCultureName.DefaultSetting = @"";
				
					colvarCultureName.ForeignKeyTableName = "medianamik_Culture";
				schema.Columns.Add(colvarCultureName);
				
				TableSchema.TableColumn colvarName = new TableSchema.TableColumn(schema);
				colvarName.ColumnName = "Name";
				colvarName.DataType = DbType.String;
				colvarName.MaxLength = 512;
				colvarName.AutoIncrement = false;
				colvarName.IsNullable = true;
				colvarName.IsPrimaryKey = false;
				colvarName.IsForeignKey = false;
				colvarName.IsReadOnly = false;
				colvarName.DefaultSetting = @"";
				colvarName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarName);
				
				TableSchema.TableColumn colvarHasModifications = new TableSchema.TableColumn(schema);
				colvarHasModifications.ColumnName = "HasModifications";
				colvarHasModifications.DataType = DbType.Boolean;
				colvarHasModifications.MaxLength = 0;
				colvarHasModifications.AutoIncrement = false;
				colvarHasModifications.IsNullable = false;
				colvarHasModifications.IsPrimaryKey = false;
				colvarHasModifications.IsForeignKey = false;
				colvarHasModifications.IsReadOnly = false;
				
						colvarHasModifications.DefaultSetting = @"((0))";
				colvarHasModifications.ForeignKeyTableName = "";
				schema.Columns.Add(colvarHasModifications);
				
				TableSchema.TableColumn colvarApprobationLevel = new TableSchema.TableColumn(schema);
				colvarApprobationLevel.ColumnName = "ApprobationLevel";
				colvarApprobationLevel.DataType = DbType.Int32;
				colvarApprobationLevel.MaxLength = 0;
				colvarApprobationLevel.AutoIncrement = false;
				colvarApprobationLevel.IsNullable = true;
				colvarApprobationLevel.IsPrimaryKey = false;
				colvarApprobationLevel.IsForeignKey = false;
				colvarApprobationLevel.IsReadOnly = false;
				colvarApprobationLevel.DefaultSetting = @"";
				colvarApprobationLevel.ForeignKeyTableName = "";
				schema.Columns.Add(colvarApprobationLevel);
				
				TableSchema.TableColumn colvarCreatedBy = new TableSchema.TableColumn(schema);
				colvarCreatedBy.ColumnName = "CreatedBy";
				colvarCreatedBy.DataType = DbType.String;
				colvarCreatedBy.MaxLength = 50;
				colvarCreatedBy.AutoIncrement = false;
				colvarCreatedBy.IsNullable = true;
				colvarCreatedBy.IsPrimaryKey = false;
				colvarCreatedBy.IsForeignKey = false;
				colvarCreatedBy.IsReadOnly = false;
				colvarCreatedBy.DefaultSetting = @"";
				colvarCreatedBy.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreatedBy);
				
				TableSchema.TableColumn colvarModifiedOn = new TableSchema.TableColumn(schema);
				colvarModifiedOn.ColumnName = "ModifiedOn";
				colvarModifiedOn.DataType = DbType.DateTime;
				colvarModifiedOn.MaxLength = 0;
				colvarModifiedOn.AutoIncrement = false;
				colvarModifiedOn.IsNullable = true;
				colvarModifiedOn.IsPrimaryKey = false;
				colvarModifiedOn.IsForeignKey = false;
				colvarModifiedOn.IsReadOnly = false;
				
						colvarModifiedOn.DefaultSetting = @"(getdate())";
				colvarModifiedOn.ForeignKeyTableName = "";
				schema.Columns.Add(colvarModifiedOn);
				
				TableSchema.TableColumn colvarModifiedBy = new TableSchema.TableColumn(schema);
				colvarModifiedBy.ColumnName = "ModifiedBy";
				colvarModifiedBy.DataType = DbType.String;
				colvarModifiedBy.MaxLength = 50;
				colvarModifiedBy.AutoIncrement = false;
				colvarModifiedBy.IsNullable = true;
				colvarModifiedBy.IsPrimaryKey = false;
				colvarModifiedBy.IsForeignKey = false;
				colvarModifiedBy.IsReadOnly = false;
				colvarModifiedBy.DefaultSetting = @"";
				colvarModifiedBy.ForeignKeyTableName = "";
				schema.Columns.Add(colvarModifiedBy);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["MedianamikProvider"].AddSchema("medianamik_NodeInstance",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("NodeInstanceId")]
		[Bindable(true)]
		public Guid NodeInstanceId 
		{
			get { return GetColumnValue<Guid>(Columns.NodeInstanceId); }
			set { SetColumnValue(Columns.NodeInstanceId, value); }
		}
		  
		[XmlAttribute("NodeId")]
		[Bindable(true)]
		public Guid NodeId 
		{
			get { return GetColumnValue<Guid>(Columns.NodeId); }
			set { SetColumnValue(Columns.NodeId, value); }
		}
		  
		[XmlAttribute("IsActive")]
		[Bindable(true)]
		public bool IsActive 
		{
			get { return GetColumnValue<bool>(Columns.IsActive); }
			set { SetColumnValue(Columns.IsActive, value); }
		}
		  
		[XmlAttribute("CreatedOn")]
		[Bindable(true)]
		public DateTime CreatedOn 
		{
			get { return GetColumnValue<DateTime>(Columns.CreatedOn); }
			set { SetColumnValue(Columns.CreatedOn, value); }
		}
		  
		[XmlAttribute("CultureName")]
		[Bindable(true)]
		public string CultureName 
		{
			get { return GetColumnValue<string>(Columns.CultureName); }
			set { SetColumnValue(Columns.CultureName, value); }
		}
		  
		[XmlAttribute("Name")]
		[Bindable(true)]
		public string Name 
		{
			get { return GetColumnValue<string>(Columns.Name); }
			set { SetColumnValue(Columns.Name, value); }
		}
		  
		[XmlAttribute("HasModifications")]
		[Bindable(true)]
		public bool HasModifications 
		{
			get { return GetColumnValue<bool>(Columns.HasModifications); }
			set { SetColumnValue(Columns.HasModifications, value); }
		}
		  
		[XmlAttribute("ApprobationLevel")]
		[Bindable(true)]
		public int? ApprobationLevel 
		{
			get { return GetColumnValue<int?>(Columns.ApprobationLevel); }
			set { SetColumnValue(Columns.ApprobationLevel, value); }
		}
		  
		[XmlAttribute("CreatedBy")]
		[Bindable(true)]
		public string CreatedBy 
		{
			get { return GetColumnValue<string>(Columns.CreatedBy); }
			set { SetColumnValue(Columns.CreatedBy, value); }
		}
		  
		[XmlAttribute("ModifiedOn")]
		[Bindable(true)]
		public DateTime? ModifiedOn 
		{
			get { return GetColumnValue<DateTime?>(Columns.ModifiedOn); }
			set { SetColumnValue(Columns.ModifiedOn, value); }
		}
		  
		[XmlAttribute("ModifiedBy")]
		[Bindable(true)]
		public string ModifiedBy 
		{
			get { return GetColumnValue<string>(Columns.ModifiedBy); }
			set { SetColumnValue(Columns.ModifiedBy, value); }
		}
		
		#endregion
		
		
			
		
		#region ForeignKey Properties
		
		#endregion
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(Guid varNodeInstanceId,Guid varNodeId,bool varIsActive,DateTime varCreatedOn,string varCultureName,string varName,bool varHasModifications,int? varApprobationLevel,string varCreatedBy,DateTime? varModifiedOn,string varModifiedBy)
		{
			NodeInstance item = new NodeInstance();
			
			item.NodeInstanceId = varNodeInstanceId;
			
			item.NodeId = varNodeId;
			
			item.IsActive = varIsActive;
			
			item.CreatedOn = varCreatedOn;
			
			item.CultureName = varCultureName;
			
			item.Name = varName;
			
			item.HasModifications = varHasModifications;
			
			item.ApprobationLevel = varApprobationLevel;
			
			item.CreatedBy = varCreatedBy;
			
			item.ModifiedOn = varModifiedOn;
			
			item.ModifiedBy = varModifiedBy;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(Guid varNodeInstanceId,Guid varNodeId,bool varIsActive,DateTime varCreatedOn,string varCultureName,string varName,bool varHasModifications,int? varApprobationLevel,string varCreatedBy,DateTime? varModifiedOn,string varModifiedBy)
		{
			NodeInstance item = new NodeInstance();
			
				item.NodeInstanceId = varNodeInstanceId;
			
				item.NodeId = varNodeId;
			
				item.IsActive = varIsActive;
			
				item.CreatedOn = varCreatedOn;
			
				item.CultureName = varCultureName;
			
				item.Name = varName;
			
				item.HasModifications = varHasModifications;
			
				item.ApprobationLevel = varApprobationLevel;
			
				item.CreatedBy = varCreatedBy;
			
				item.ModifiedOn = varModifiedOn;
			
				item.ModifiedBy = varModifiedBy;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn NodeInstanceIdColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn NodeIdColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn IsActiveColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn CreatedOnColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        public static TableSchema.TableColumn CultureNameColumn
        {
            get { return Schema.Columns[4]; }
        }
        
        
        
        public static TableSchema.TableColumn NameColumn
        {
            get { return Schema.Columns[5]; }
        }
        
        
        
        public static TableSchema.TableColumn HasModificationsColumn
        {
            get { return Schema.Columns[6]; }
        }
        
        
        
        public static TableSchema.TableColumn ApprobationLevelColumn
        {
            get { return Schema.Columns[7]; }
        }
        
        
        
        public static TableSchema.TableColumn CreatedByColumn
        {
            get { return Schema.Columns[8]; }
        }
        
        
        
        public static TableSchema.TableColumn ModifiedOnColumn
        {
            get { return Schema.Columns[9]; }
        }
        
        
        
        public static TableSchema.TableColumn ModifiedByColumn
        {
            get { return Schema.Columns[10]; }
        }
        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string NodeInstanceId = @"NodeInstanceId";
			 public static string NodeId = @"NodeId";
			 public static string IsActive = @"IsActive";
			 public static string CreatedOn = @"CreatedOn";
			 public static string CultureName = @"CultureName";
			 public static string Name = @"Name";
			 public static string HasModifications = @"HasModifications";
			 public static string ApprobationLevel = @"ApprobationLevel";
			 public static string CreatedBy = @"CreatedBy";
			 public static string ModifiedOn = @"ModifiedOn";
			 public static string ModifiedBy = @"ModifiedBy";
						
		}
		#endregion
		
		#region Update PK Collections
		
        #endregion
    
        #region Deep Save
		
        #endregion
	}
}
